package com.cold.manage.service.impl;

import com.alibaba.fastjson2.JSON;
import com.cold.common.domain.DeviceDetails;
import com.cold.common.utils.JedisUtils;
import com.cold.manage.mapper.DeviceDetailsMapper;
import com.cold.manage.service.*;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DeviceDetailsServiceImpl implements IDeviceDetailsService {

    @Resource
    private DeviceDetailsMapper deviceDetailsMapper;

    @Override
    public void saveDeviceDetailsToRedis() {
        List<DeviceDetails> list = deviceDetailsMapper.selectDeviceDetails();
        Jedis jedis = JedisUtils.getInstance().getJedis();
        list.forEach(deviceDetails -> {
            jedis.set(deviceDetails.getDeviceCode(),JSON.toJSONString(deviceDetails));
        });
    }
}
